//
//  BaseNavigationController.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/23.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class BaseNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //为了能手势拉回来,要加代理
        interactivePopGestureRecognizer?.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //自定义
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //进入首页时候不运行下面的代码
        if childViewControllers.count != 0 {
        let btn = UIButton(title: "返回", backImageName: nil, color: UIColor.orangeColor(), fontSize: 14, imageName: "navigationbar_back_withtext")
        //用自定义的按钮替换返回键
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        
        //隐藏下面的tabBar
        viewController.hidesBottomBarWhenPushed = true
        
        btn.addTarget(self, action: "popBack", forControlEvents: .TouchUpInside)
        }
        super.pushViewController(viewController, animated: true)
    }

    @objc private func popBack() {
        popViewControllerAnimated(true)
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
